package ling.common;

import cn.hutool.core.date.DateUtil;
import lombok.var;

import java.util.Date;

public class IDCardHelper {
    /**  true女，默认男
     *
     * @param idCard
     * @return
     */
    public static boolean getGender(String idCard) {
        boolean gender = false;
        char c = idCard.charAt(idCard.length() - 2);
        if (c % 2 == 0) {
            gender = true;
        }
        return gender;
    }
    public static Date birthday(String idCard) {
        // 出生日期
        String birthday = "";
        var sfzh = idCard;
        if (sfzh.length() == 15) {
            birthday = "19" + sfzh.substring(6, 8) + "-" + sfzh.substring(8, 10) + "-" + sfzh.substring(10, 12);
        } else if (sfzh.length() == 18) {
            birthday = sfzh.substring(6, 10) + "-" + sfzh.substring(10, 12) + "-" + sfzh.substring(12, 14);
        }
       var date= DateUtil.parse(birthday);
        return date;
    }
    public static int age(String idCard){
        var date= birthday(idCard);
        return DateUtil.age(date,new Date());
    }
}
